from google.appengine.api import users
from django.http import HttpResponseRedirect

class access(object):
  def __init__(self, group, redirect_url):
    self.group = group
    self.redirect_url = redirect_url
    
  def __user_in_group(self):
    if self.group == 'admin' and users.is_current_user_admin():
      return True
    elif self.group == 'logged_in' and users.get_current_user():
      return True
    elif self.group == 'public':
      return True
    return False
    
  def __call__(self, f):
    def wrapper(*args, **kwargs):
      return self.__user_in_group() and f(*args, **kwargs) or HttpResponseRedirect(self.redirect_url)
    return wrapper